package com.artPreter.service.impl;

import com.artPreter.mapper.EventExhibitionBannerMapper;
import com.artPreter.pojo.EventExhibitionBanner;
import com.artPreter.service.IEventExhibitionBannerService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 活动展览轮播图片表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2025-01-09
 */
@Service
public class EventExhibitionBannerServiceImpl extends ServiceImpl<EventExhibitionBannerMapper, EventExhibitionBanner> implements IEventExhibitionBannerService {

    @Override
    public List<EventExhibitionBanner> getList(EventExhibitionBanner eventExhibitionBanner) {
        LambdaQueryWrapper<EventExhibitionBanner> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EventExhibitionBanner::getStatus,1);
        List<EventExhibitionBanner> result= this.baseMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public IPage<EventExhibitionBanner> getPage(Integer currentPage, Integer size, EventExhibitionBanner eventExhibitionBanner) {
        IPage<EventExhibitionBanner> eventExhibitionBannerIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<EventExhibitionBanner> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EventExhibitionBanner::getStatus,1);
        eventExhibitionBannerIPage = this.baseMapper.selectPage(eventExhibitionBannerIPage, queryWrapper);
        return eventExhibitionBannerIPage;
    }

    @Override
    public void add(EventExhibitionBanner eventExhibitionBanner) {
        eventExhibitionBanner.setStatus(1);
        // 生成UUID并设置到实体对象中
        String uuid = UUID.randomUUID().toString();
        eventExhibitionBanner.setBannerId(uuid);
        this.baseMapper.insert(eventExhibitionBanner);
    }

    @Override
    public void edit(EventExhibitionBanner eventExhibitionBanner) {
        this.baseMapper.updateById(eventExhibitionBanner);
    }

    @Override
    public void delete(EventExhibitionBanner eventExhibitionBanner) {
        eventExhibitionBanner.setStatus(0);
        this.baseMapper.updateById(eventExhibitionBanner);
    }
}
